﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class UserControl_ucOrder : System.Web.UI.UserControl
{
    TblOrderDAO orderDAO = new TblOrderDAO(Global.CONNECTION_STRING);
    DateTime _dt;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // hien thi ngay dau tien va cuoi cung cua thang

            _dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime date = _dt;
            date = date.AddMonths(1);
            date = date.AddDays(-(_dt.Day));

            txtFrDate.Text = _dt.ToString("dd/MM/yyy");
            txtToDate.Text = DateTime.Now.ToString("dd/MM/yyyy");

            // so sanh hai ngay
            RangeValidator1.MinimumValue = new DateTime(1600, 01, 01).ToString("dd/MM/yyyy");
            RangeValidator1.MaximumValue = new DateTime(9999, 12, 31).ToString("dd/MM/yyyy");
            RangeValidator2.MinimumValue = new DateTime(1600, 01, 01).ToString("dd/MM/yyyy");
            RangeValidator2.MaximumValue = new DateTime(9999, 12, 31).ToString("dd/MM/yyyy");
        }
        if (Request.Params["__EVENTTARGET"] != null)
        {
            if (Request.Params["__EVENTTARGET"].IndexOf("DataPagerImages") > 0)
            {
                LoadOrderList();
            }
        }
    }
   
    private void LoadOrderList()
    {
        try
        {
            DataTable dt = orderDAO.GetOrderLst(Global.ConvertToDate(txtFrDate.Text), Global.ConvertToDate(txtToDate.Text), ((TblUserAccount)Session[Global.SESSION_LOGGED_USER]).Email);
            lvItem.DataSource = dt;
            lvItem.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        LoadOrderList();
    }

    protected void lvItem_SelectedIndexChanged(object sender, EventArgs e)
    {
        lvItem.DataBind();
    }
    protected void DataPagerImages_PreRender(object sender, EventArgs e)
    {
        lvItem.DataBind();
    }
}
